package com.fz.mapper;

import com.fz.entity.GoodsReview;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
public interface GoodsReviewMapper extends BaseMapper<GoodsReview> {
    List<GoodsReview> getLatestReviews(Long productId, int limit);

    Double getAverageRating(Long productId);

    @Select("SELECT product_id, rating, COUNT(*) as count " +
            "FROM goods_review " +
            "WHERE rating BETWEEN 1 AND 5 " +
            "GROUP BY product_id, rating")
    List<Map<Long, Object>> getRatingDistribution();
}
